﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using AirCondition.Data;


namespace AirCondition.HR
{
    public partial class AddEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql="INSERT INTO [tb_EemployeeInfo] ([ename], [egender], [ebirth], [enativeplace], [eidentification], [estatus], [ecellphone], [etelephone], [eaddress], [edepartment], [eposition], [ejobtype], [esalary], [ecardname], [esalarycard], [esalarycardbank], [ecardpoint], [ecardownerrelationship], [ephoto], [eidscanner]) VALUES (@ename, @egender, @ebirth, @enativeplace, @eidentification, @estatus, @ecellphone, @etelephone, @eaddress, @edepartment, @eposition, @ejobtype, @esalary, @ecardname, @esalarycard, @esalarycardbank, @ecardpoint, @ecardownerrelationship, @ephoto, @eidscanner)";
            SqlParameter[] sqlPara = { new SqlParameter("@ename", SqlDbType.NVarChar),
                                       new SqlParameter("@egender", SqlDbType.NVarChar), 
                                       new SqlParameter("@ebirth", SqlDbType.VarChar), 
                                       new SqlParameter("@enativeplace", SqlDbType.NVarChar),
                                       new SqlParameter("@eidentification", SqlDbType.VarChar), 
                                       new SqlParameter("@estatus", SqlDbType.NVarChar),
                                       new SqlParameter("@ecellphone", SqlDbType.VarChar),
                                       new SqlParameter("@etelephone", SqlDbType.VarChar), 
                                       new SqlParameter("@eaddress", SqlDbType.NVarChar),
                                       new SqlParameter("@edepartment", SqlDbType.NVarChar), 
                                       new SqlParameter("@eposition", SqlDbType.NVarChar), 
                                       new SqlParameter("@ejobtype", SqlDbType.NVarChar),
                                       new SqlParameter("@esalary", SqlDbType.VarChar), 
                                       new SqlParameter("@ecardname", SqlDbType.NVarChar),
                                       new SqlParameter("@esalarycard", SqlDbType.VarChar),
                                       new SqlParameter("@esalarycardbank", SqlDbType.NVarChar), 
                                       new SqlParameter("@ecardpoint", SqlDbType.NVarChar),       
                                       new SqlParameter("@ecardownerrelationship", SqlDbType.NVarChar),
                                       new SqlParameter("@ephoto", SqlDbType.Image),
                                       new SqlParameter("@eidscanner", SqlDbType.Image),                             
                                     };

            sqlPara[0].Value = TextBox1.Text.Trim();
            sqlPara[1].Value = DropDownList1.SelectedItem.Text.Trim();
            sqlPara[2].Value = TextBox2.Text.Trim();
            sqlPara[3].Value = TextBox3.Text.Trim();
            sqlPara[4].Value = TextBox4.Text.Trim();

            sqlPara[5].Value = TextBox5.Text.Trim();
            sqlPara[6].Value = TextBox6.Text.Trim();
            sqlPara[7].Value = TextBox7.Text.Trim();
            sqlPara[8].Value = DropDownList2.SelectedItem.Text.Trim();
            sqlPara[9].Value = TextBox8.Text.Trim();


            sqlPara[10].Value = TextBox9.Text.Trim();
            sqlPara[11].Value = DropDownList3.SelectedItem.Text.Trim();
            sqlPara[12].Value = TextBox10.Text.Trim();

            sqlPara[13].Value = TextBox11.Text.Trim();
            sqlPara[14].Value = TextBox12.Text.Trim();
            sqlPara[15].Value = TextBox13.Text.Trim();

            sqlPara[16].Value = TextBox14.Text.Trim();

            sqlPara[17].Value = Data.PhotoRW.PhotoToArray(SaveFile(FileUpload1));
            sqlPara[18].Value = Data.PhotoRW.PhotoToArray(SaveFile(FileUpload2));

            int rows = new SQLHelp().ExecuteNonQuery(sql, sqlPara, ConfigurationManager.AppSettings["SQLServer"]);
            //int rows = ExecuteNonQuery(sql, sqlPara, ConfigurationManager.AppSettings["SQLExpress"]);

            Response.Write("<script language='javascript'>alert('添加成功');</script>");
        }


        private string SaveFile(FileUpload up)
        {
            //string file = "~/uploadfiles/";
            string file = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()) + "uploadfiles\\";

            if (!System.IO.Directory.Exists(file))
            {
                System.IO.Directory.CreateDirectory(file);
            }
            file = file + up.FileName;
            up.SaveAs(file);
            //return file + up.FileName;
            return file;
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            string sql = "INSERT INTO [tb_EemployeeInfo] ([ename], [egender], [ebirth], [enativeplace], [eidentification], [estatus], [ecellphone], [etelephone], [eaddress], [edepartment], [eposition], [ejobtype], [esalary], [ecardname], [esalarycard], [esalarycardbank], [ecardpoint], [ecardownerrelationship], [ephoto], [eidscanner]) VALUES (@ename, @egender, @ebirth, @enativeplace, @eidentification, @estatus, @ecellphone, @etelephone, @eaddress, @edepartment, @eposition, @ejobtype, @esalary, @ecardname, @esalarycard, @esalarycardbank, @ecardpoint, @ecardownerrelationship, @ephoto, @eidscanner)";
            SqlParameter[] sqlPara = { new SqlParameter("@ename", SqlDbType.NVarChar),
                                       new SqlParameter("@egender", SqlDbType.NVarChar), 
                                       new SqlParameter("@ebirth", SqlDbType.VarChar), 
                                       new SqlParameter("@enativeplace", SqlDbType.NVarChar),
                                       new SqlParameter("@eidentification", SqlDbType.VarChar), 
                                       new SqlParameter("@estatus", SqlDbType.NVarChar),
                                       new SqlParameter("@ecellphone", SqlDbType.VarChar),
                                       new SqlParameter("@etelephone", SqlDbType.VarChar), 
                                       new SqlParameter("@eaddress", SqlDbType.NVarChar),
                                       new SqlParameter("@edepartment", SqlDbType.NVarChar), 
                                       new SqlParameter("@eposition", SqlDbType.NVarChar), 
                                       new SqlParameter("@ejobtype", SqlDbType.NVarChar),
                                       new SqlParameter("@esalary", SqlDbType.VarChar), 
                                       new SqlParameter("@ecardname", SqlDbType.NVarChar),
                                       new SqlParameter("@esalarycard", SqlDbType.VarChar),
                                       new SqlParameter("@esalarycardbank", SqlDbType.NVarChar), 
                                       new SqlParameter("@ecardpoint", SqlDbType.NVarChar),       
                                       new SqlParameter("@ecardownerrelationship", SqlDbType.NVarChar),
                                       new SqlParameter("@ephoto", SqlDbType.Image),
                                       new SqlParameter("@eidscanner", SqlDbType.Image),                             
                                     };

            sqlPara[0].Value = TextBox1.Text.Trim();
            sqlPara[1].Value = DropDownList1.SelectedItem.Text.Trim();
            sqlPara[2].Value = TextBox2.Text.Trim();
            sqlPara[3].Value = TextBox3.Text.Trim();
            sqlPara[4].Value = TextBox4.Text.Trim();
            sqlPara[5].Value = TextBox5.Text.Trim();
            sqlPara[6].Value = TextBox6.Text.Trim();
            sqlPara[7].Value = TextBox7.Text.Trim();
            sqlPara[8].Value = DropDownList2.SelectedItem.Text.Trim();
            sqlPara[9].Value = TextBox8.Text.Trim();
            sqlPara[10].Value = TextBox9.Text.Trim();
            sqlPara[11].Value = DropDownList3.SelectedItem.Text.Trim();
            sqlPara[12].Value = TextBox10.Text.Trim();
            sqlPara[13].Value = TextBox11.Text.Trim();
            sqlPara[14].Value = TextBox12.Text.Trim();
            sqlPara[15].Value = TextBox13.Text.Trim();
            sqlPara[16].Value = TextBox14.Text.Trim();
            sqlPara[17].Value = TextBox15.Text.Trim();

            sqlPara[18].Value = Data.PhotoRW.PhotoToArray(SaveFile(FileUpload1));
            sqlPara[19].Value = Data.PhotoRW.PhotoToArray(SaveFile(FileUpload2));

            int rows = new SQLHelp().ExecuteNonQuery(sql, sqlPara, ConfigurationManager.AppSettings["SQLServer"]);
            //int rows = ExecuteNonQuery(sql, sqlPara, ConfigurationManager.AppSettings["SQLExpress"]);

            Response.Write("<script language='javascript'>alert('添加成功');</script>");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Write("<script language=javascript>history.go(-2);</script>");
        }

    }
}
